import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../teacher-competition-system/StuDemo/StuIndex.vue'
import StuInfoShow from "@/teacher-competition-system/RootDemo/StuInfoShow.vue";
import TeaInfoShow from "@/teacher-competition-system/RootDemo/TeaInfoShow.vue";
import CpShow from "@/teacher-competition-system/RootDemo/CpShow.vue";
import AtShow from "@/teacher-competition-system/RootDemo/AtShow.vue";
import IndexShow from "@/teacher-competition-system/RootDemo/IndexShow.vue";


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  linkActiveClass: "active",
  routes: [
    // {
    //   path: '/',
    //   name: 'home',
    //   component: HomeView
    // },
    // {
      // path: '/about',
      // name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      // component: () => import('../views/AboutView.vue')
    // },
    {
      path: '/RootLogin',
      name: 'RootLogin',
      component: () => import('../teacher-competition-system/LoginDemo/RootLogin.vue')
    },
    {
      path: '/UserLogin',
      name: 'UserLogin',
      component: () => import('../teacher-competition-system/LoginDemo/UserLogin.vue')
    },
    {
      path: '/UserRegister',
      name: 'UserRegister',
      component: () => import('../teacher-competition-system/RegisterDemo/UserRegister.vue')
    },
    {
      path: '/AtShow',
      name: 'AtShow',
      component: () => import('../teacher-competition-system/RootDemo/AtShow.vue')
    },
    {
      path: '/CpShow',
      name: 'CpShow',
      component: () => import('../teacher-competition-system/RootDemo/CpShow.vue')
    },
    {
      path: '/IndexShow',
      name: 'IndexShow',
      component: () => import('../teacher-competition-system/RootDemo/IndexShow.vue')
    },
    {
      path: '/RootIndex',
      name: 'RootIndex',
      component: () => import('../teacher-competition-system/RootDemo/RootIndex.vue'),
      redirect:'/index',
      meta:{requiresAuth:true},
      children:[
        {
          path:'/index',
          component:IndexShow
        },
        {
          path:'/student',
          component:StuInfoShow
        },
        {
          path:'/teacher',
          component:TeaInfoShow
        },
        {
          path:'/cp',
          component:CpShow
        },
        {
          path:'/ac',
          component:AtShow
        }
      ]
    },
    {
      path: '/StuInfoShow',
      name: 'StuInfoShow',
      component: () => import('../teacher-competition-system/RootDemo/StuInfoShow.vue')
    },
    {
      path: '/TeaInfoShow',
      name: 'TeaInfoShow',
      component: () => import('../teacher-competition-system/RootDemo/TeaInfoShow.vue')
    },
    {
      path: '/',
      name: 'StuIndex',
      component: () => import('../teacher-competition-system/StuDemo/StuIndex.vue')
    },
    {
      path: '/StuInfo',
      name: 'StuInfo',
      component: () => import('../teacher-competition-system/StuDemo/StuInfo.vue'),
      beforeEnter: (to, from, next) => {
      if(localStorage.getItem('token') == null){
        if(to.path == '/stuinfo'){
          next('userlogin')
      }
        }else{
      next()
    }
  
    }
    },
    {
      path: '/StuSign',
      name: 'StuSign',
      component: () => import('../teacher-competition-system/StuDemo/StuSign.vue'),
      beforeEnter: (to, from, next) => {
      if(localStorage.getItem('token') == null){
        if(to.path == '/stusign'){
          next('userlogin')
      }
        }else{
      next()
    }
  
    }
    },
    {
      path: '/TeaIndex',
      name: 'TeaIndex',
      component: () => import('../teacher-competition-system/TeaIndex/TeaIndex.vue')
    },
    {
      path: '/TeaInfo',
      name: 'TeaInfo',
      component: () => import('../teacher-competition-system/TeaIndex/TeaInfo.vue')
    },
    {
      path: '/TeaRelease',
      name: 'TeaRelease',
      component: () => import('../teacher-competition-system/TeaIndex/TeaRelease.vue')
    },
    {
      path: '/competition',
      name: 'competition',
      component: () => import('../teacher-competition-system/StuDemo/Competition.vue')
    },
    {
    path: '/activity',
    name: 'activity',
    component: () => import('../teacher-competition-system/StuDemo/Activity.vue')
    },
    {
      path: '/search',
      name: 'search',
      component: () => import('../teacher-competition-system/StuDemo/Search.vue')
    },
    {
      path: '/information',
      name: 'information',
      component: () => import('../teacher-competition-system/StuDemo/InformationDetails.vue')
    },
    {
      path: '/perinfo',
      name :'perinfo',
      component : () => import('../teacher-competition-system/StuDemo/PersonalInformation.vue')
    }
  ]
})


// router.beforeEach((to,from,next) => {
//   if(localStorage.getItem('token') == null){
//     if(to.path !== '/userlogin'){
//       next('/userlogin')
//     }
//   }
//   next()
// })

// beforeEnter: (to, from, next) => {
//   if(localStorage.getItem('token') == null){
//     if(to.path == '/stusign'){
//       next('userlogin')
//     }
//   }
// }

export default router
